package com.etc.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.etc.entity.BlogComnent;
import com.etc.entity.UBB;
import com.etc.service.BlogComnentService;
import com.etc.utils.CommonMessage;

@Controller
@RequestMapping(value = "Userapi")
public class BlogComnentController {

	@Resource
	private BlogComnentService blogComnentService;

	@RequestMapping(value = "listBlogToBefore")
	public String listBlog(Model model) {
		List<BlogComnent> list = blogComnentService.getBlogComnent();
		model.addAttribute("list", list);
		list.forEach(System.out::println);
		return "user/blog";
	}

	@RequestMapping(value = "listBlogSingle")
	public String listBlogSingle01(int bid, Model model) {
		System.out.println("bid************:" + bid);

		// List<BlogComnent> list = blogComnentService.getBlogComnentByBid(bid);

		/*
		 * Blog blog = list.get(0).getBlog(); list.forEach(System.out::println);
		 */
		// model.addAttribute("blog", blog);

		List<UBB> list = blogComnentService.getUBB(bid);
		model.addAttribute("list", list);
		return "user/blog-single";

	}
	
	@RequestMapping(value="addcomment")
	@ResponseBody
	public CommonMessage addBlogcomment(Integer uid,String bccontent,Integer bid) {
		CommonMessage cm = new CommonMessage();
		BlogComnent bc = new BlogComnent();
		bc.setBid(bid);
		bc.setUid(uid);
		bc.setBccontent(bccontent);
		boolean flag =blogComnentService.addcomment(bc);
		cm.setMsg(flag?"评论成功":"评论失败");
		return cm;
		
	}

}
